package com.cjl.algorithm;

public class KMPTest {

    /**
     * 暴力匹配
     * @param ts
     * @param ps
     * @return
     */
    public static int bf(String ts,String ps){
        char[] tsc = ts.toCharArray();
        char[] psc = ps.toCharArray();

        int i=0;
        int j=0;
        while (i < tsc.length && j < psc.length){
            if (tsc[i] == psc[j]){
                i++;
                j++;
            }else {
                i=i-j+1;
                j=0;
            }
        }
        if (j==psc.length){
            return i-j;
        }
        return -1;
    }
}
